# Maintainer: Paweł Tomak <pawel@tomak.eu>
pkgname=pike
_pkgname=Pike
pkgver=8.0.702
pkgrel=1
pkgdesc="Pike Programing language"
url="https://pike.lysator.liu.se"
arch="x86_64"
license="GPL-2.0-or-later"
options="!check" # there are no tests for those packages
depends="readline"
makedepends="gmp-dev
	bzip2-dev
	freeglut-dev
	gdbm-dev
	giflib-dev
	giflib-utils
	gtk+2.0
	libglade-dev
	libsm-dev
	mesa-gl
	nettle
	nettle-dev
	nettle-utils
	pcre-dev
	sdl-dev
	sdl_mixer-dev
	sqlite-dev
	sqlite-libs
	zlib-dev
	librsvg-dev"
subpackages="$pkgname-doc $pkgname-full::noarch"
source="http://pike.lysator.liu.se/pub/pike/all/$pkgver/$_pkgname-v$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-v$pkgver"

_full_deps="$pkgname=$pkgver-r$pkgrel $pkgname-doc=$pkgver-r$pkgrel"
for _name in bzip2 gdbm gl gtk image pcre sdl svg sqlite
do
	subpackages="$subpackages $pkgname-$_name"
	_full_deps="$_full_deps $pkgname-$_name=$pkgver-r$pkgrel"
done

build() {
	make CONFIGUREARGS=" \
		--prefix=/usr \
		--disable-make_conf \
		--disable-noopty-retry \
		--without-cdebug \
		--without-bundles \
		--without-ssleay \
		--with-gmp \
		--with-crypt \
		--with-bignums \
		--without-rtldebug \
		--with-Bz2 \
		--without-fftw \
		--without-_Ffmpeg \
		--with-gdbm \
		--without-GTK1 \
		--with-GTK2 \
		--with-jpeglib \
		--without-Kerberos \
		--without-msql \
		--without-mysql \
		--without-Odbc \
		--without-oracle \
		--with-GL \
		--with-GLUT \
		--with-_Regexp_PCRE \
		--without-libpdf \
		--without-sass \
		--with-sane \
		--with-SDL \
		--with-SDL_Mixer \
		--with-svg \
		--with-tifflib \
		--without-freetype \
		--without-vcdiff \
		--with-_Image_WebP \
		--with-zlib"
	PATH="$builddir/bin:$PATH" make doc
}

package() {
	make INSTALLARGS="--traditional" buildroot="$pkgdir" install
}

_install() {
	local _arg
	for _arg; do
		[ -e "$_arg" ] || continue
		local bn=$(basename "$_arg")
		local dn=$(dirname "$_arg")
		mkdir -p "$subpkgdir/$dn"
		mv "$_arg" "$subpkgdir/$dn/$bn"
	done
}

bzip2() {
	cd "$pkgdir"
	pkgdesc="$pkgname support"
	depends="pike"
	_install usr/lib/pike/modules/*Bz2.*
}

gdbm() {
	cd "$pkgdir"
	pkgdesc="$pkgname GDBM support"
	depends="pike"
	_install usr/lib/pike/modules/*Gdbm.*
}

gl() {
	cd "$pkgdir"
	pkgdesc="$pkgname OpenGL/GLUT support"
	depends="pike freeglut libsm"
	_install usr/lib/pike/modules/*GL*
}

gtk() {
	cd "$pkgdir"
	pkgdesc="$pkgname GTK2 support"
	depends="pike-image"
	_install usr/lib/pike/modules/*GTK2*
	_install usr/lib/pike/modules/Tools.pmod/PV.pike
}

image() {
	cd "$pkgdir"
	pkgdesc="$pkgname image handling modules"
	depends="pike libjpeg tiff libwebp"
	_install usr/lib/pike/?.?/modules/Image.pmod
	_install usr/lib/pike/modules/Image.so
	_install usr/lib/pike/modules/*Image_[!S]*.so
	_install usr/lib/pike/modules/*Image*.pmod
	_install usr/lib/pike/modules/Graphics.pmod
	_install usr/lib/pike/modules/Colors.pmod
	_install usr/lib/pike/modules/Protocols.pmod/X.pmod/XImage.pmod
}

pcre() {
	cd "$pkgdir"
	pkgdesc="$pkgname PCRE support"
	depends="pike"
	_install usr/lib/pike/modules/*Regexp_PCRE.*
}

sdl() {
	cd "$pkgdir"
	pkgdesc="$pkgname SDL support"
	depends="pike-image"
	_install usr/lib/pike/modules/*SDL.*
}

svg() {
	cd "$pkgdir"
	pkgdesc="$pkgname SVG support"
	depends="pike"
	_install usr/lib/pike/modules/_Image_SVG.so
}

sqlite() {
	cd "$pkgdir"
	pkgdesc="$pkgname SQLite support"
	depends="pike"
	_install usr/lib/pike/modules/*SQLite.*
	_install usr/lib/pike/modules/Sql.pmod/sqlite*
}

doc() {
	cd "$pkgdir"
	mkdir -p usr/share/doc/
	mv "$builddir/refdoc/traditional_manual/" usr/share/doc/pike/
	rm -rf usr/doc/
	default_doc
}

full() {
	depends="$_full_deps"
	pkgdesc="Meta package for Pike Programing Language"
	mkdir -p "$subpkgdir"
}

sha512sums="67ee5a6af9e7ab1031c63647d0f351b6f9a29a736f6b049beada577997bab199d542d39c16c328a81ea52821555f8db9bd227caad55fed9c3613ba6718124e09  Pike-v8.0.702.tar.gz"
